package com.maxlen.admin.security;

import com.maxlen.common.exception.ExceptionCode;
import com.maxlen.common.utils.R;
import com.maxlen.common.utils.ResponseUtils;
import com.maxlen.common.utils.ResultCode;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 用户未登录处理
 */
@Component
public class CustomAuthenticationEntryPoint implements AuthenticationEntryPoint {
    @Override
    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException {
        ResponseUtils.out(response, R.error(ExceptionCode.USER_NOT_LOGIN));
    }
}
